#pragma once

#include "png8cropfx.h"

namespace png8crop
{
	union size2d
	{
		struct{	png_uint_32 w, h; };
		png_uint_32 values[2];
	
		png_uint_32 get_area()
		{
			return (this->w * this->h);
		}
	};

	union point2d
	{
		struct{	png_uint_32 x, y; };
		png_uint_32 values[2];
	};

	union crop
	{
		struct{	point2d orig; size2d size; };
		struct{	png_uint_32 x, y, w, h; };
		png_uint_32 values[4];
	};

	class imgsource
	{
	protected:
		size2d size;
		int bit_depth, color_type;

		png_bytepp rows;

		png_colorp palette;
		int num_palette;

		png_bytep trans_alpha;
		int num_trans;
		png_color_16p trans_color;

	public:
		imgsource(void);
		~imgsource(void);
		
		size2d get_size() { return this->size; }

		void save(FILE* dest);
		void save(FILE* dest, crop *crop_info);

	private:
		void save(FILE* dest, size2d *crop_size, png_bytepp crop_rows);

		
	public:
		void static print_version_info(void);
	};
}